//{=============================================================================
//! @file      The_Set.h
//! @date      2014-04-17 22:01:24 +0400
//! @author    Roman Anufriev <mrspeedstalker@gmail.com>
//!
//! @brief     Header file that allows you to work with the set.
//!
//!            It contains all necessary instruments to correctly work with the
//!            set.
//}=============================================================================

#ifndef __THE_SET_H_INCLUDED
#define __THE_SET_H_INCLUDED

#include <stdlib.h>
#include <string.h>
#include <assert.h>

//! As the library was written in C only, this is convenient enum.
enum boolean
	{
	false,
	true
	};

//{=============================================================================
//! @brief    Structure of the set.
//! 
//!           Consists of pointer to the next set structure and
//!           (void*) pointer to the data stored in one element of the set.
//}=============================================================================
struct theSet_elem
	{
	struct theSet_elem* next;
	void*               elem_t;
	};

//{=============================================================================
//! `theSet_construct` - constructs good set.
//!
//! @param    ** theSet_head    address of the pointer to the first element of
//!                             the set, e.g. address of theSet_head.
//}=============================================================================
void theSet_construct (struct theSet_elem** theSet_head);

//{=============================================================================
//! `theSet_destruct` - destructs a set in a proper way.
//!
//! @param    ** theSet_head    address of the pointer to the first element of
//!                             the set, e.g. adress of theSet_head.
//}=============================================================================
void theSet_destruct  (struct theSet_elem** theSet_head);


// /\-/\-/\-/\-/\-/\-/\-/\-/\-/\-/\-/\-/\-/\-/\-/\-/\-/\-/\-/\-/\-/\-/\-/\-/\-/\
// \/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/


//{=============================================================================
//! `theSet_add` - adds an element to the set.
//!
//! @param     **theSet_head      address of the pointer to the first element
//!                               of the set, e.g. address of theSet_head;
//!
//! @param     *new_elem_t        address of the element you want to add to the
//!                               set;
//!
//! @param     sizeof_new_elem_t  size of the element you want to add;
//!
//! @param     *compare(...)      pointer to the comparing function.
//!
//!
//! @return    true               if the element has been successfully added;
//!            false              if the element has not been added.
//}=============================================================================
enum boolean theSet_add  (struct theSet_elem** theSet_head,
						  void*                new_elem_t,
						  size_t               sizeof_new_elem_t,
						  int    (*compare)(const void* p1, const void* p2));

//{=============================================================================
//! `theSet_delete` - deletes an element from the set.
//!
//! @param     **theSet_head         address of the pointer to the first element
//!                                  of the set, e.g. address of theSet_head;
//!
//! @param     *elem_to_del          address of the element you want to delete
//!                                  from the set;
//!
//! @param     sizeof_elem_t_to_del  size of the element you want to delete;
//!
//! @param     *compare(...)         pointer to the comparing function.
//!
//!
//! @return    true                  if the element has been successfully
//!                                    deleted;
//!            false                 if the element has not been deleted.
//}=============================================================================
enum boolean theSet_delete (struct theSet_elem** theSet_head,
						    void*                elem_to_del,
						    size_t               sizeof_elem_t_to_del,
						    int    (*compare)(const void* p1, const void* p2));


#endif // __THE_SET_H_INCLUDED

